#!/bin/bash

set -x
exec 1>/var/log/$(basename $0).log 2>&1
#enable i2c interface
dtparam i2c_arm=on
modprobe i2c-dev

sleep 5
for loop in 1 2 3 4 5
do
    is_1a=$(i2cdetect -y  1 0x1a 0x1a | egrep "(1a|UU)" | awk '{print $2}')

    if [ "x${is_1a}" != "x" ] ; then
        echo "install wm8960-soundcard"
        dtoverlay wm8960-soundcard
        sleep 1

        rm /etc/asound.conf
        rm /var/lib/alsa/asound.state

        echo "create wm8960-soundcard configure file"
        ln -s /etc/wm8960-soundcard/asound.conf /etc/asound.conf

        echo "create wm8960-soundcard status file"
        ln -s /etc/wm8960-soundcard/wm8960_asound.state /var/lib/alsa/asound.state
        break
    fi
    sleep 3
done

alsactl restore
